package com.tedu.API.homeWork;

import javafx.concurrent.Worker;

import java.util.ArrayList;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class homeWork2 {
    public static void main(String[] args) {
        //创建List，在 List 中增加三个工人
        List<worker2> list=new ArrayList<>();
        list.add(new worker2("zhang3",18,3000));
        list.add(new worker2("li4",25,3500));
        list.add(new worker2("wang5",22,3200));

        //在 li4 之前插入一个工人
        list.add(1,new worker2("zhao6",24,3300));
        //删除wang5
        list.remove(3);
        //遍历打印工人数据
        for (int i=0;i<list.size();i++){
            System.out.println("所有工人信息"+list.get(i));
        }
        //利用 forEach 遍历，打印输出所有年龄大于 20 的工人信息
//        List<Integer> years=list.stream()
//                .map(worker2 -> worker2.getYear())
//                .collect(Collectors.toList());
//        IntStream.range(0,years.size())
//                .forEach(i -> {
//                    if (years.get(i)>20){
//                        System.out.println("大于20岁的工人信息:"+list.get(i));
//                    }
//                });
        list.stream()
                .filter(worker2 -> worker2.getYear()>20)
                .forEach(worker2 -> System.out.println("年龄大于20工人的信息"+worker2));

        //使用for循环，打印输出工人姓名长度大于 6 的信息。
         //因为工人里面名字长度没有大于6，所以不会输出
        List<worker2> name=list.stream()
                .filter(worker2 -> worker2.getName().length()>6)
                .collect(Collectors.toList());
        for (int i=0;i<name.size();i++){
            System.out.println("名字大于6"+list.get(i));
        }
    }
}
//worker类，薪资，年龄，姓名
class worker2{
    private String name;
    private int year;
    private int salary;

    //set和get

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    //构造函数

    public worker2() {
    }

    public worker2(String name, int year, int salary) {
        this.name = name;
        this.year = year;
        this.salary = salary;
    }

    //toString方法

    public String toString() {
        return "名字"+name+" "
                +"年龄"+year+" "
                +"薪资"+salary;
    }

    public boolean equals(Object obj) {
        return super.equals(obj);
    }
}
